package com.yuexun.dhdoctor.module.survey.presenter.impl;


import com.yuexun.dhdoctor.base.BaseEntity;
import com.yuexun.dhdoctor.module.survey.bean.StartSurveyBean;
import com.yuexun.dhdoctor.module.survey.bean.SurveyAnswerDtlBean;
import com.yuexun.dhdoctor.module.survey.bean.SurveyDtlBean;
import com.yuexun.dhdoctor.module.survey.model.ISurveyModel;
import com.yuexun.dhdoctor.module.survey.presenter.ISurveyDtlPresenter;
import com.yuexun.dhdoctor.module.survey.ui.view.ISurveyDtlView;

import org.kymjs.kjframe.ui.ViewInject;

import java.util.Map;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by wangt on 2017/8/22.
 */

public class SurveyDtlPresenter implements ISurveyDtlPresenter {
    private ISurveyModel model;
    private ISurveyDtlView view;

    public SurveyDtlPresenter(ISurveyModel model, ISurveyDtlView view) {
        this.model = model;
        this.view = view;
    }

    @Override
    public void startSurvey(Map<String, String> praise) {
        model.startSurvey(praise)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<BaseEntity<StartSurveyBean>>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        ViewInject.toast("请检查网络状态");
                    }

                    @Override
                    public void onNext(BaseEntity<StartSurveyBean> bean) {
                        view.startSurvey(bean);
                    }
                });
    }

    @Override
    public void getSurveyDtl(Map<String, String> praise) {
        model.getSurveyDtl(praise)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<BaseEntity<SurveyDtlBean>>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        ViewInject.toast("请检查网络状态");
                    }

                    @Override
                    public void onNext(BaseEntity<SurveyDtlBean> bean) {
                        view.showSurveyDtl(bean);
                    }
                });
    }

    @Override
    public void getSurveyAnswerDtl(Map<String, String> praise) {
        model.getSurveyAnswerDtl(praise)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<BaseEntity<SurveyAnswerDtlBean>>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        ViewInject.toast("请检查网络状态");
                    }

                    @Override
                    public void onNext(BaseEntity<SurveyAnswerDtlBean> bean) {
                        view.showSurveyAnswerDtl(bean);
                    }
                });
    }
}
